/****************************************************************************
*
* Description: Resource descriptor class
* Created at: 03.12.06 13:05:34 UTC
*
* $Revision$
*
****************************************************************************/
#if !defined(__common_resource_descriptor_h__)
#define __common_resource_descriptor_h__

#include <string>
#include <map>
#include <boost/any.hpp>
#include <common/functional.h>
#include <common/resource.h>

namespace common {

/* Basic resource extender. Allows assign for some kind of resources
 * dynamic properties with string key.  */
class resource_descriptor
	: public resource_t
{
	using resource_t::id_type;
public:
	/* Properties container.  */
	typedef	std::map<std::string, boost::any> container_t;

    /* Ctor.  */
	resource_descriptor (id_type id) :
		resource_t(id)
	{}

	/* Copy ctor.  */
	resource_descriptor (const resource_descriptor& o) :
		resource_t(o),
		properties_(o.properties_)
	{}

	/* Property map index operator.  */
	container_t::mapped_type& operator [] (const char* key)
	{
		return properties_[key];
	}

	/* Return true if property exists.  */
	bool has_property (const char* key)
	{
		return properties_.find(key) != properties_.end();
	}

	/* Debug stuff.  */
    virtual void dump (std::ostream& o)
    {
    	this->resource_t::dump(o);
    	common::output_map_to_stream<container_t> show_map(o, "\n");
		show_map(properties_);
    }

	/* Serialization stuff.  */
    virtual void serialize (std::ostream& o)
    {
    	this->resource_t::serialize(o);
    }

    virtual void deserialize (std::istream& i)
    {
    	this->resource_t::deserialize(i);
    }

private:
	/* Data members.  */
	container_t properties_;
};

} /* End of common namepspace.  */

#endif  /* End of __common_resource_descriptor_h__.  */
